#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
#include<unistd.h>
#include<sys/mman.h>

int main()
{
    const int SIZE = 4096;

    //只读模式打开共享内存文件
    const char* name = "os";
    int fd = shm_open(name, O_RDONLY, 0666);
    
    //映射到进程地址空间
    void *ptr = mmap(0, SIZE, PROT_READ, MAP_SHARED, fd, 0);
    printf("收到如下消息:\n%s\n",(char*)ptr);

    printf("按任意键结束\n");
    char ch = getchar();
    //删除共享文件
    shm_unlink(name);
}